﻿#region "Copyright (C) Lenny Granovsky. 2011-2013"
//    This library provides extended cache capabilities to the ASP.NET applications.
//
//                Copyright (C) Lenny Granovsky. 2011-2013. 
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//    This program comes with ABSOLUTELY NO WARRANTY.
//    This is free software, and you are welcome to redistribute it
//    under certain conditions;
#endregion

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

namespace FlexiCache
{
    /// <summary>
    /// Class provides object collection functionality for session data.
    /// This class is not intended to be used directly. The RuntimeContext should be used instead.
    /// </summary>
    [Serializable()]
    public class SessionObjectCollection : ApplicationObjectCollection
    {
        internal SessionObjectCollection()
            : base()
        {
        }
    }

    /// <summary>
    /// Class provides object collection functionality for application data.
    /// This class is not intended to be used directly. The RuntimeContext should be used instead.
    /// </summary>
    [Serializable()]
    public class ApplicationObjectCollection : NameObjectCollectionBase
    {
        internal ApplicationObjectCollection()
            : base()
        {
        }

        public void Add(string name, object value)
        {
            base.BaseAdd(name, value);
        }

        public void Clear()
        {
            base.BaseClear();
        }

        public object Get(int index)
        {
            return base.BaseGet(index);
        }

        public object Get(string name)
        {
            return base.BaseGet(name);
        }

        public string GetKey(int index)
        {
            return base.BaseGetKey(index);
        }

        public void Lock()
        {
        }

        public void Remove(string name)
        {
            base.BaseRemove(name);
        }

        public void RemoveAll()
        {
            this.Clear();
        }

        public void RemoveAt(int index)
        {
            base.BaseRemoveAt(index);
        }

        public void Set(string name, object value)
        {
            base.BaseSet(name, value);
        }

        public void Set(int index, object value)
        {
            base.BaseSet(index, value);
        }

        public void UnLock()
        {
        }

        public string[] AllKeys
        {
            get
            {
                return base.BaseGetAllKeys();
            }
        }

        public ApplicationObjectCollection Contents
        {
            get
            {
                return this;
            }
        }

        public override int Count
        {
            get
            {
                return base.Count;
            }
        }

        public object this[int index]
        {
            get
            {
                return this.Get(index);
            }
            set
            {
                this.Set(index, value);
            }
        }

        public object this[string name]
        {
            get
            {
                return this.Get(name);
            }
            set
            {
                this.Set(name, value);
            }
        }

        public bool Contains(string name)
        {
            return this.AllKeys.Contains(name);
        }

        public bool ContainsAndNotNull(string name)
        {
            if (!this.Contains(name))
                return false;
            return (this[name] != null);
        }
    }
}
